function initData(page_index) {
$.ajax({
		url : $("#Pagination").attr("url"),
		type : "post",
		cache : false,
		data : {
			currentPage : page_index,
			pageSize : $("#Pagination").attr("pageSize"),
			role: $("#role").val(),
			beginDate:$("#dpd1").val(),
			endDate:$("#dpd2").val(),
			sex:$("#sexs").val(),
			username: $("#usernames").val(),
			specialtyArea: $("#specialtyAreas").val()
		},
		success : function(data) {
			var json=eval("("+data+")");
			$("#Pagination").attr("recordCount",json.recordCount);
			$("#expTable").empty(); 			
			var str='';
			for(var i=0;i<json.users.length;i++){
				str+='<tr><td><input type="checkbox" class="checkboxes" value="'+json.users[i].userId+'" ></td><td>'+json.users[i].username+'</td><td>'+json.users[i].sex+'</td><td>'+(json.users[i].addTime).substring(0,10)+'</td><td>'+json.users[i].role
				     +'</td><td>';
			if(json.users[i].specialtyArea!=null && json.users[i].specialtyArea.length>10){
				str+=(json.users[i].specialtyArea).substring(0,10);
			}else{
				str+=json.users[i].specialtyArea;
			}
			str+='</td><td><a type="'+json.users[i].userId+'" onclick="view(this)">查看</a> | '	
			     +'<a type="'+json.users[i].userId+'" onclick="vote(this)">授权</a> | '
			     +'<a target="_blank" type="'+json.users[i].userId+'" onclick="del(this)">删除</a></td></tr>';
			}
			$("#expTable").append(str);
			$.fn.refreshPagination(page_index);
		},
		error : function(xhr) {
			alert("点击过快，正在加载，请稍后再次点击!"+xhr.statusText);
		}
	});
	jQuery('#sample_1 .group-checkable').attr("checked", false);
}

function del(obj){
	if(obj!=undefined){
		if(!window.confirm("你确定要删除这条数据吗？删除过后不可恢复")){
			return ;
		}
		$.post("delUser", { userId: obj.type},function(data){
			initData(1);
		});
	}else{
		alert("用户不存在！");
	}
	
}

function vote(obj){
	if(obj!=undefined){
		document.role_form.reset();
		$('#myModal').modal({
			  keyboard: false
		});
	    $("#userId").val(obj.type);
	    $.post("showUserRole", { userId: obj.type},function(data){
			var selector="input[type=radio][value="+data+"]";
			$(selector).attr("checked",'checked');
		});
	}else{
		alert("用户不存在！");
	}
}

function view(obj){
	if(obj!=undefined){
		$.post("getUserInfo", { userId: obj.type},function(data){
			var json=eval("("+data+")");
			$("#username").add("#sex").add("#addTime").add("#urole").add("#specialtyArea").text("");
			$("#username").text(json.username);
			$("#sex").text(json.sex);
			$("#addTime").text(json.addTime);
			$("#urole").text(json.role);
			$("#specialtyArea").text(json.specialtyArea);
			$('#userModal').modal({
				  keyboard: false
			});
		});
	}else{
		alert("用户不存在！");
	}
	
}
